package mysql

type AdminRole struct {
	Id         uint `gorm:"column:id;primary_key" json:"id" form:"id"`
	Status     int  `gorm:"column:status" json:"status" form:"status"`
	Deleted    int  `gorm:"column:deleted" json:"deleted"`
	AddTime    int32 `gorm:"column:add_time" json:"add_time"`
	UpdateTime int32 `gorm:"column:update_time" json:"update_time"`
	Memo       string `gorm:"column:memo" json:"memo" form:"memo"`
	IdAdmin uint
	IdRole  uint

}
//这一步的意思是改表明的  默认表明是带s的
func (AdminRole) TableName() string  {
	return "k_admin_role_item"
}


func (a AdminRole) GetRidByAdmin(adminId uint) uint{
	var arole AdminRole
	Db.Select("id_role").Where("id_admin = ?",adminId).Find(&arole)
	return arole.IdRole
}

func (a AdminRole) Save(ar AdminRole)error{
	db := Db
	err := db.Save(&ar).Error
	return err
}

func (a AdminRole) DelByAdminId(adminId uint)error{
	db := Db
	ar := AdminRole{}
	err := db.Where("id_admin = ?",adminId).Delete(&ar).Error
	return err
}


